package com.hqyj.paimaisys.util;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hqyj.paimaisys.model.Auction;
import com.hqyj.paimaisys.service.AuctionService;
import com.hqyj.paimaisys.service.DealrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class JobUtil {

    @Autowired
    private AuctionService auctionService;

    @Autowired
    private DealrecordService dealrecordService;

    // @Scheduled(cron = "1/30 * * * * ?")
    public void startAuction(){
        //开启 今天开始竞拍的商品
        UpdateWrapper<Auction> wrapper = new UpdateWrapper<Auction>();
        //封装 新的状态
        wrapper.set("state", Auction.STATUS_AUCTING);

        //封装 stime = 今天
        wrapper.eq("stime", LocalDate.now());
        //封装 state = 审核通过
        wrapper.eq("state",Auction.STATUS_PASS);

        //List<Auction> list = auctionService.list();
        boolean flag = auctionService.update(wrapper);
        //upate autition set state = ? where ? ?
    }

    //@Scheduled(cron = "1/30 * * * * ?")
    public void endAuction(){
          auctionService.endAuction();
    }

    @Scheduled(cron = "1/30 * * * * ?")
    public void weiyue(){
        dealrecordService.weiyue();
    }
}
